﻿<UserControl
    x:Class="DvachBrowser3.Views.Partial.BoardThreadRefList"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:DvachBrowser3.Views.Partial"
    xmlns:local2="using:DvachBrowser3"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:vm="using:DvachBrowser3.ViewModels"
    xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
    xmlns:behaviors="using:DvachBrowser3.Behaviors"
    mc:Ignorable="d"
    d:DesignHeight="300"
    d:DesignWidth="400">
    
    <UserControl.Resources>
        <local2:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter" />
    </UserControl.Resources>

    <Grid>
        <ListView x:Name="MainList" ItemsSource="{x:Bind ViewModel.Threads, Mode=OneWay}" SelectionMode="None" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
            <ListView.Header>
                <StackPanel>
                    <local:BannerView ViewModel="{x:Bind ViewModel.Banner, Mode=OneWay}" x:Name="Banner" HorizontalAlignment="Center" Margin="5" 
                                      Visibility="{x:Bind ShowBanner, Mode=OneWay, Converter={StaticResource BoolToVisibilityConverter}, ConverterParameter=false}"
                                      ToolTipService.ToolTip="{x:Bind ViewModel.Banner.BannerLinkTitle, Mode=OneWay}"
                                      BannerTapped="Banner_OnBannerTapped"/>
                    <TextBlock Text="{x:Bind ListTitle, Mode=OneWay}" FontWeight="SemiBold" FontSize="{x:Bind StyleManager.Text.TitleFontSize, Mode=OneWay}" MaxLines="2" Margin="0, 0, 0, 10" HorizontalAlignment="Center" TextWrapping="Wrap" />
                </StackPanel>
            </ListView.Header>
            <ListView.ItemContainerStyle>
                <Style TargetType="ListViewItem">
                    <Setter Property="HorizontalContentAlignment" Value="Stretch" />
                    <Setter Property="Padding" Value="0" />
                    <Setter Property="Template" Value="{StaticResource CleanListItem}" /> 
                </Style>
            </ListView.ItemContainerStyle>
            <ListView.ItemTemplate>
                <DataTemplate x:DataType="vm:IThreadPreviewViewModel">
                    <Border Tag="{x:Bind}" Tapped="ThreadElement_OnTapped" BorderThickness="0, 0, 0, 1" BorderBrush="{ThemeResource SystemControlBackgroundChromeMediumBrush}">
                        <Border.Background>
                            <SolidColorBrush Opacity="0" />
                        </Border.Background>
                        <local:BoardThreadRefPreview ViewModel="{x:Bind Mode=OneWay}" Margin="0, 5, 10, 5" />
                        <interactivity:Interaction.Behaviors>
                            <behaviors:PopupMenuBehavior>
                                <behaviors:PopupMenuBehavior.MenuFlyout>
                                    <MenuFlyout>
                                        <MenuFlyoutItem Text="Открыть тред" Tag="{x:Bind}" Click="OpenThreadFlyoutItem_OnClick" />
                                        <MenuFlyoutItem Text="Прочитано" Tag="{x:Bind}" Click="MarkAsReadFlyoutItem_OnClick" />
                                    </MenuFlyout>
                                </behaviors:PopupMenuBehavior.MenuFlyout>
                            </behaviors:PopupMenuBehavior>
                        </interactivity:Interaction.Behaviors>
                    </Border>
                </DataTemplate>
            </ListView.ItemTemplate>
            <ListView.Footer>
                <Border Margin="0, 15, 0, 0">
                    <StackPanel>
                        <TextBlock Margin="5" FontSize="{x:Bind StyleManager.Text.NormalFontSize, Mode=OneWay}">
                            <Run>Скорость доски: </Run>
                            <Run Text="{x:Bind ViewModel.BoardSpeed, Mode=OneWay}" FontWeight="SemiBold" />
                        </TextBlock>
                    </StackPanel>
                </Border>
            </ListView.Footer>
        </ListView>
    </Grid>
</UserControl>
